/**
 * 版权所有（c）2021. 上海海鼎信息工程股份有限公司，保留所有权利
 */
package com.lovely602.design.behavior.interpreter.demo;

/**
 * 环境类
 *
 * @author lizhixing
 */
public class Context {

  private String[] citys = { "韶关", "广州" };
  private String[] persons = { "老人", "妇女", "儿童" };
  private Expression cityPerson;

  public Context() {
    Expression city = new TerminalExpression(citys);
    Expression person = new TerminalExpression(persons);
    cityPerson = new AndExpression(city, person);
  }

  public void freeRide(String info) {
    boolean ok = cityPerson.interpret(info);
    if (ok) {
      System.out.println("您是" + info + "，您本次乘车免费！");
    } else {
      System.out.println(info + "，您不是免费人员，本次乘车扣费2元！");
    }
  }
}
